package com.sskj.fabi.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.fabi.bean.FabiBuyBean;
import com.sskj.fabi.bean.FabiListBean;
import com.sskj.fabi.bean.PayWayBean;
import com.sskj.fabi.http.HttpConfig;
import com.sskj.fabi.ui.fragment.TradingHallBuyFragment;
import com.sskj.lib.SPConfig;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;

public class TradingHallBuyPresenter extends BasePresenter<TradingHallBuyFragment> {
    /**
     * 获取用户交易大厅数据
     */

    public void getFabiList(int page, int size, boolean isBuy) {
        httpService.getFbList(page, size, isBuy)
                .execute(new JsonCallBack<HttpData<PageBean<FabiListBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<PageBean<FabiListBean>>> response) {
                        HttpData<PageBean<FabiListBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            if (httpData.getData().getList().size() == 0 && page != 1) {
                                ToastUtil.showShort("亲，已经到底了");
                            } else {
                                mView.setData(httpData.getData());
                            }
                        } else {
                            ToastUtil.showShort(httpData.getMsg());
                        }
                    }

                });
    }

    /**
     * 下单
     */

    public void order(String tpwd, String order_no, String total_num, String total_price, boolean isBuy) {
        httpService.coinOrder(tpwd, order_no, total_num, total_price, isBuy ? 1 : 2)
                .execute(new JsonCallBack<HttpData<FabiBuyBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<FabiBuyBean>> response) {
                        if (response.body().getStatus() == HttpConfig.OK) {
                            mView.checkOk(response.body().getData().getDealEntrustNo(), !isBuy);
                        }
                        ToastUtil.showShort(response.body().getMsg());
                    }
                });
    }


}
